import axios from 'axios'
import { baseUrl } from "@/utils/constant"

const service = axios.create({
    baseURL: baseUrl,
    withCredentials: false
})

service.interceptors.request.use(
    async config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

service.interceptors.response.use(
    (response) => {
        return Promise.resolve(response.data)
    },
    error => {
        const response = error.response
        return Promise.reject((response && response.data ? response.data : null) || { cancel: error.name === 'CanceledError', status: false, timeout: (error.message || '').includes("timeout") })
    }
)

export default service
